package com.xufx.thread.liaoxuefeng.thread13_ConcurrentSets;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by xufx on 2022/1/5 12:27
 * 在thread10中实现了一个BlockingQueue。当一个线程调用这个queue的getTask方法时，内部会让线程变成等待状态，直到队列的条件满足不为空，
 * 线程被唤醒后，getTask()方法才回返回
 * 因为BlockingQueue非常有用，Java的并发包java.util.concurrent提供了安全的集合：ArrayBlockingQueue.
 * java并发集合类：List、Map、Set、Deque对应的并发集合如下：
 * --------------------------------------------------------------------------------
 * |interface    |non-thread-safe    |thread-safe                                  |
 * |-------------|-------------------|---------------------------------------------|
 * |List         |ArrayList          |CopyOnWriteArrayList                         |
 * |-------------|-------------------|---------------------------------------------|
 * |Map          |HashMap            |ConcurrentHashMap                            |
 * |-------------|-------------------|---------------------------------------------|
 * |Set          |HashSet/TreeSet    |CopyOnWriteArraySet                          |
 * |-------------|-------------------|---------------------------------------------|
 * |Queue        |ArrayDeque         |ArrayBlockingQueue                           |
 * |             |LinkedList         |LinkedBlocingQueue                           |
 * |-------------|-------------------|---------------------------------------------|
 * |Deque        |ArrayDeque         |LinkedBlockingQueue                          |
 * |             |LinkedList         |                                             |
 * |-------------|-------------------|---------------------------------------------|
 *
 * 使用并发集合与使用非线程安全的集合类完全相同。
 */
public class Main {
    public static void main(String[] args) {
        Map unsafeMap = new HashMap<>();
        Map safeMap = Collections.synchronizedMap(unsafeMap);
        System.out.println(System.identityHashCode(unsafeMap));
        System.out.println(System.identityHashCode(safeMap));
    }
}
